/*
 * @lc app=leetcode.cn id=860 lang=javascript
 *
 * [860] 柠檬水找零
 */

// @lc code=start
/**
 * @param {number[]} bills
 * @return {boolean}
 */
var lemonadeChange = function(bills) {
    let count_5=0
    let count_10=0
    for(let i=0;i<bills.length;i++){
        if(bills[i]==5)count_5++
        else if(bills[i]==10){
            if(count_5==0){
                return false
            }
            count_5--
            count_10++
        }else{
            if(count_5==0)return false
            if(count_10>0){
                count_10--;count_5--
            }else{
                count_5=count_5-3;
                if(count_5<0)return false
            }
        }
    }
    return true
};
// @lc code=end

